import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import Controllers.GlobalData;
import Controllers.GenericToolsForController.RequestMainStatusEnum;
import Controllers.GenericToolsForController.RequestStepStatusEnum;
import Entity.Request;
import Entity.RequestStatusHistory;
import Entity.Status;
import Entity.User;
import Entity.Worker;
import fit.ActionFixture;


public class ReviewAndDecisionRequest extends ActionFixture{
	
	
	int chairManId;
	int requestId;
	List<Request> requestsList;
	private static String LocalNetworkConfigurtaion = "ConfigServerOption.txt";
	
	
	public ReviewAndDecisionRequest()
	{
		
	}
	
	
	
	//Connect to the Server.
		public void enterToSystem()
		{
			/*
			  in the System we have:
			  initiator  -  id 3
			  2 chairman shimon1171 - id 62, guyp = id 2.
			  There are 5 request:
				request No 21, here chairman are shimon1171 , the Ststus is: OPEN, REV_REVIEWED_CLOSE.
				request No 22, here chairman are shimon1171 , the Ststus is: OPEN, TST_PASSED.
				request No 23, here chairman are shimon1171 , the Ststus is: OPEN, EXE_PASSED.
				request No 24, here chairman are shimon1171 , the Ststus is: SUSPEND, TST_PASSED.
				request No 25, here chairman are guyp , the Ststus is: OPEN, TST_PASSED
			 */
			
			Request req;
			requestsList = new ArrayList<Request>();
			
			Worker chairman_62,chairman_2;
			chairman_62 = new Worker(1, 62, "shimon", "Arzuan", "icmbraudesys@gmail.com", "0508-1234567", "shimon1171", "2" );
			chairman_2 = new Worker(2, 2, "guy", "peleg", "icmbraudesys@gmail.com", "0508-1234567", "guyp", "2" );
			User initiator = new User(3, "Ron", "Rosesnfeld","icmbraudesys@gmail.com", "0508-1234567", "roon", "Student");		

			//the current worker that log to the system
			GlobalData.worker = chairman_62;
					
			req = new Request();
			req.setRequestId(21);
			req.setChairman(chairman_62);
			req.setInitiator(initiator);
			Status status = new Status(RequestStepStatusEnum.EVL_PASSED, RequestMainStatusEnum.OPEN); 
			RequestStatusHistory cureentStatus = new RequestStatusHistory(1, status, new Date(), new Date(), null, null, null);
			req.setCurrentStatus(cureentStatus);
			requestsList.add(req);
			
			
			req = new Request();
			req.setRequestId(22);
			req.setChairman(chairman_62);
			req.setInitiator(initiator);
			status = new Status(RequestStepStatusEnum.REV_REVIEWED_EXTENDED, RequestMainStatusEnum.OPEN); 
			cureentStatus = new RequestStatusHistory(2, status, new Date(), new Date(), null, null, null);
			req.setCurrentStatus(cureentStatus);
			requestsList.add(req);
			
			
			req = new Request();
			req.setRequestId(23);
			req.setChairman(chairman_62);
			req.setInitiator(initiator);
			status = new Status(RequestStepStatusEnum.REV_REVIEWED_EXTENDED_DENY, RequestMainStatusEnum.OPEN); 
			cureentStatus = new RequestStatusHistory(3, status, new Date(), new Date(), null, null, null);
			req.setCurrentStatus(cureentStatus);
			requestsList.add(req);
			
			
			req = new Request();
			req.setRequestId(24);
			req.setChairman(chairman_62);
			req.setInitiator(initiator);
			status = new Status(RequestStepStatusEnum.REV_REVIEWED_TIME_EXTENSION_PENDING, RequestMainStatusEnum.OPEN); 
			cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
			req.setCurrentStatus(cureentStatus);
			requestsList.add(req);	
			
			/*
			req = new Request();
			req.setRequestId(25);
			req.setChairman(chairman_2);
			req.setInitiator(initiator);
			status = new Status(RequestStepStatusEnum.REV_REVIEWED_CLOSE, RequestMainStatusEnum.OPEN); 
			cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
			req.setCurrentStatus(cureentStatus);
			requestsList.add(req);
			*/
			
		}
		
		public void requestNumber(int number)
		{
			this.requestId = number;
		}
		
		public void chairManId(int number)
		{
			this.chairManId=number;
		}
	
	
		public boolean reviewRequest(int op)
		{
					//op is a variable which stands for the decision of the chairman 
					//	0 for deny, 1  for approve, 2 for more details.
			switch (op)
			{
				case 0:
				for(Request req : requestsList)
						if(req.getRequestId() == requestId)
								return req.reviewDenied();
					return false;		
				case 1:
				for(Request req : requestsList)
						if(req.getRequestId() == requestId)
									return req.reviewApproved();
					return false;	
				case 2:
					for(Request req : requestsList)
					     if(req.getRequestId() == requestId)
								return req.moreDetailsNeeded();
					return false;	
			}
			return false;
		}
}
